<?php

namespace App\Admin\Controllers;

use App\Models\Team;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;

class TeamController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(Team::with(['user']), function (Grid $grid) {
            $grid->model()->orderByDesc('id');
            $grid->column('id')->sortable();
            $grid->column('user_id');
            $grid->column('user.email', '用户邮箱');
            $grid->column('user.mobile', '用户手机号');
            $grid->column('name');
            $grid->column('area');
            $grid->column('head_img')->image(env("API_URL"), 50, 50);
            $grid->column('area_img')->image(env("API_URL"), 50, 50);;
            $grid->column('status')->using([0 => '待审核', 1 => '已通过', 2 => '已驳回']);
            $grid->column('created_at');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->equal('user_id');
                $filter->equal('user.email', '用户邮箱');
                $filter->equal('user.mobile', '用户手机号');
            });
            $grid->disableCreateButton();
            $grid->disableBatchActions();
            $grid->disableRowSelector();
            $grid->disableViewButton();
            $grid->disableDeleteButton();
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(Team::with(['user']), function (Form $form) {
            $form->display('user_id', __('用户id'))->readonly();
            $form->display('user.email', __('用户邮箱'))->readonly();
            $form->display('user.mobile', __('用户手机号'))->readonly();
            $form->image('head_img', __('门头照片'))->readonly();
            $form->image('area_img', __('办公区域照片'))->readonly();
            $form->text('name', __('社区名字'))->readonly();
            $form->text('area', __('办公面积'))->readonly();

            $form->radio('status', __('审核'))->options([1 => '通过', 2 => '驳回', 0 => '审核中']);
            $form->footer(function ($footer) {
                // 去掉`查看`checkbox
                $footer->disableViewCheck();
                // 去掉`继续编辑`checkbox
                $footer->disableEditingCheck();
                // 去掉`继续创建`checkbox
                $footer->disableCreatingCheck();
            });
            $form->disableViewButton();
            $form->disableDeleteButton();
        });
    }
}
